from typing import *


class Solution:
    def queryResults(self, limit: int, queries: List[List[int]]) -> List[int]:
        h = Counter()
        c = Counter()
        ans = []
        tot = 0
        for x, y in queries:
            if c[x] != 0:
                h[c[x]] -= 1
                if h[c[x]] == 0:
                    tot -= 1
            c[x] = y
            h[y] += 1
            if h[y] == 1:
                tot += 1
            ans.append(tot)
        return ans
